﻿using FreeDream.Common;
using log4net;
using Microsoft.AspNetCore.Builder;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FreeDream.Infrastructure
{
    /// <summary>
    /// MiniProfiler性能分析
    /// </summary>
    public static class MiniProfilerMiddleware
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof(MiniProfilerMiddleware));
        public static void UseMiniProfilerMiddleware(this WebApplication app)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            try
            {
                if (AppSettings.App("Startup", "MiniProfiler", "Enabled").ObjToBool())
                {
                    // 性能分析
                    app.UseMiniProfiler();

                }
            }
            catch (Exception ex)
            {
                Log.Error($"An error was reported when starting the MiniProfilerMildd.\n{ex.Message}");
                throw;
            }


        }
    }
}
